<?php
Class Menu extends AppModel{
	var $name = 'Menu';
	var $displayField = 'descripcion';
	var $useTable = 'menus';
	
	function countMenu($params){
		return $this->find('count',$params);
	}
	function dataMenu($params){
		return $this->find('all',$params);
	}
	function getMenu($params = null){
		
		$sql="SELECT
	            node.id as \"Tqcmenu__id\",
	            node.name  as \"Tqcmenu__descripcion\",
	            node.controller || '/' || node.action  as \"Tqcmenu__url\",
	            (COUNT(parent.name) - 1) AS \"Tqcmenu__level\",
	            node.lft  as \"Tqcmenu__lft\",
	            node.rght  as \"Tqcmenu__rgt\"
	            FROM menus AS node,
	            	menus AS parent
	            WHERE node.lft BETWEEN parent.lft AND parent.rght
	            GROUP BY node.name, node.id, node.controller,node.action,node.lft,node.rght
	            ORDER BY node.lft";
            
		return $this->query($sql);
		
	}
}
?>